<?php 
include 'includes/login_check.php';
//Gets the id of the challenge to view, if not there, redirect to home page
if (isset($_GET['challenge_id'])) {
	$challenge_id = $_GET['challenge_id'];	
} else {
    header("location: $home");
}
//CHECK IF CONTEST IS FULL

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<?php include 'includes/head.php' ?>
	<link href="css/custom.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="js/battle.js"></script>
    <link rel="stylesheet" type="text/css" href="lightbox/lightbox.css" media="screen" />
    <script type="text/javascript" src="lightbox/jquery.lightbox-0.5.js"></script>
	
	<!--Confirm box before form is submitted-->
	<script type="text/javascript">
    $(document).ready(function() {
	$('#contestant_form').submit(function() {
    var c = confirm("Once you submit your image, it is final. There is no way of modifying an incorrect image. We'd recommend double checking to make sure you uploaded the correct image. Would you like to submit anyway?");
    return c; //you can just return c because it will be true or false
	});
	});
	
	</script>
    
  

</head>

<body class="view_challenge">



<div id="top">
    <div id="header">
        <?php include 'includes/nav_container.php' ?>
    </div>
</div>

<div id="wrapper">
    <table>
    	<tr>
        	<td id="col-left">
            	<?php include 'includes/current_activity.php'; ?>
            </td>
        	<td id="col-main">
            
            <?php 
			//Get contest info 
				$sqlquery=mysql_query("SELECT * FROM challenges WHERE id = '$challenge_id'");
				if (!$result) {
					 header("location: $home");

				}
				while($row = mysql_fetch_assoc($sqlquery)) {
					$title = $row['title'];
					$description = $row['description'];	
					$win_by_votes = $row['win_by_votes'];
					$win_by_time = $row['win_by_times'];
					$created_on = $row['created_on'];
					$end_time = $row['ended_on'];
					if ($row['private'] == '0') {
						$private = 'private';
					} else {
						$private = 'public';
					}
				}

			?>
            
            
            	<div>
                    <div class="main-title">
                        <h2>
                        	<span>Join - <?php echo $title ?></span>
                            <br class="cleft" />
                        </h2>
                    </div>
                    <div class="main-content">
                        <form action="join_contest_process.php" id="contestant_form" method="post" enctype="multipart/form-data">
                            <div class="block-left battlepage_container">
                                <div class="desc">
                                	<p>CONTEST DESCRIPTION: <?php echo $description ?></p>
                                    <p class="tips">Better images mean more votes. Make it a good image.</p>
                                </div>
                                <div class="upload">
                                	<input type="file" name="file" id="file" />
									Description:<textarea name="description">200 characters or less!</textarea>
                                    <input type="hidden" name="challenge_id"  value="<?php echo $challenge_id ?>" /> 
                                </div>
                            </div>
                            <div class="block-right submit">
                                <input type="submit" id="submit"  value=""><br /><br />
                                <h1>Challenge Info</h1><br />
                                <p>Challenge Ends: <?php 
								
								// contest end by votes and time	
								if (isset($win_by_votes) && isset($win_by_time) && $win_by_time != 0 && $win_by_votes != 0){
									echo "The challenge ends when either $win_by_votes votes is reached for a single contestant, or on $end_time, whichever comes first.";
								}
								
								// contest end by votes 	
								elseif (isset($win_by_votes) && (!isset($win_by_time) || $win_by_time == 0) && $win_by_votes != 0) {
									echo "The challenge ends when $win_by_votes votes is reached for a single contestant.";
								}
								
								// contest end by time 	
								else {
									echo "The challenge ends on $end_time.";
								}
								
								?></p><br />
                                <p>Public/Private: This contest is <?php echo $private ?></p><br />
                            </div>
                        </form>
                    </div>
                </div>   
            </td>
        	<!--<td id="col-right"></td>-->
        </tr>
    </table>
</div>

<div id="bottom">
</div>

</body>

</html>
